<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑节点</title>
    <c:import url="../../header.jsp"/>
</head>
<body>

<div class="content-warp">
    <div class="bg-warp">
        <form id="addProcess" action="">
        <table class="dggui-table-info">
            <tbody>
            <tr>
                <th>业务类型：</th>
                <c:if test="${empty rzFlow.businessName}">
                    <td name="busyt">${rzFlow.bigformatName}</td>
                </c:if>
                <c:if test="${not empty rzFlow.businessName}">
                    <td name="busyt">${rzFlow.businessName}</td>
                </c:if>
                <th>产品名称：</th>
                <td name="busyt">${rzFlow.productName}</td>
          <%--      <th>商品名称：</th>
                <td name="busyt">${rzFlow.goodsName}</td>
                <th>渠道名称：</th>
                <td name="busyt">${rzFlow.channelName}</td>--%>
                <th>业务办理周期：</th>
                <td name="bldate">${rzFlow.managementCycle}天</td>
            </tr>
            <tr>
                <th>工作日/自然日：</th>
                <c:if test="${rzFlow.isnaturalorworkday==1}"><td>工作日</td></c:if>
                <c:if test="${rzFlow.isnaturalorworkday==2}"><td>自然日</td></c:if>
                <th>审核级数：</th>
                <c:if test="${rzFlow.examineGrade==1}"><td>一级</td></c:if>
                <c:if test="${rzFlow.examineGrade==2}"><td>二级</td></c:if>
                <c:if test="${rzFlow.examineGrade==3}"><td>三级</td></c:if>
                <c:if test="${rzFlow.examineGrade==4}"><td>四级</td></c:if>
                <c:if test="${rzFlow.examineGrade==5}"><td>五级</td></c:if>
                <c:if test="${rzFlow.examineGrade==6}"><td>六级</td></c:if>
                <c:if test="${rzFlow.examineGrade==7}"><td>七级</td></c:if>
                <c:if test="${rzFlow.examineGrade==8}"><td>八级</td></c:if>
                <c:if test="${rzFlow.examineGrade==9}"><td>九级</td></c:if>
                <c:if test="${rzFlow.examineGrade==10}"><td>十级</td></c:if>
            </tr>
            </tbody>
        </table>
        </form>
        <table class="dggui-table cell-border table-form nodeTable">
            <thead>
            <th>序号</th>
            <th>节点名称</th>
            <th>节点办理周期（天）</th>
            <th>工作日/自然人</th>
            <th>关联字段</th>

            <th>是否扣罚</th>
            <th>扣罚方案</th>
            <th>是否预警</th>

            <th>是否关键节点</th>
            <th colspan="2">操作</th>
            </thead>
            <tbody id="tb">
            <tr>
                <%--<input type="hidden" value="${nodeJd.id}">--%>
                <td>${nodeJd.sort}</td>
                <td>${nodeJd.name}</td>
                <td>${nodeJd.handleDate}</td>
                <td><input type="hidden" value="${nodeJd.isNaturalorWorkday}">
                    <c:if test="${nodeJd.isNaturalorWorkday == 1}">工作日</c:if>
                    <c:if test="${nodeJd.isNaturalorWorkday == 2}">自然日</c:if>
                </td>
                <td>
                    <c:if test="${empty nodeJd.relationField}">
                        <a href="javascript:void(0)" class="dggui-link dggui-icon-btn" onclick="relevanceCode(this)"><i class="iconfont icon-tianjia"></i><span>添加关联字段</span></a>
                    </c:if>
                    <c:if test="${not empty nodeJd.relationField}">
                        <span class="relevance">
                            ${nodeJd.relationField}
                        </span>
                        <a href="javascript:void(0)" class="dggui-icon-btn" onclick="relevanceCode(this,'${nodeJd.relationFieldIds}')"><i class="iconfont icon-bianji1"></i></a>
                    </c:if>
                </td>

                <td>
                    <select class="dggui-select">
                        <option value="1" <c:if test="${nodeJd.isPunish == 1}">selected</c:if>>是</option>
                        <option value="2" <c:if test="${nodeJd.isPunish == 2}">selected</c:if>>否</option>
                    </select>
                    <%--<input type="hidden" value="${nodeJd.isPunish}">
                    <c:if test="${nodeJd.isPunish == 1}">是</c:if>
                    <c:if test="${nodeJd.isPunish != 1}">否</c:if>--%>
                </td>
                <td>
                    <select class="dggui-select">
                        <option value="">请选择</option>
                        <c:forEach items="${kfList}" var="kfList">
                            <option value="${kfList.id}" <c:if test="${nodeJd.punishId == kfList.id}">selected</c:if>>${kfList.name}</option>
                        </c:forEach>
                    </select>
                    <%--<input type="hidden" value="${nodeJd.punishId}">
                    <c:if test="${nodeJd.punishId == 1}">是</c:if>
                    <c:if test="${nodeJd.punishId != 1}">否</c:if>--%>
                </td>
                <td>
                    <select class="dggui-select">
                        <option value="1" <c:if test="${nodeJd.isWarning == 1}">selected</c:if>>是</option>
                        <option value="2" <c:if test="${nodeJd.isWarning == 2}">selected</c:if>>否</option>
                    </select>
                    <%--<input type="hidden" value="${nodeJd.isWarning}">
                    <c:if test="${nodeJd.isWarning == 1}">是</c:if>
                    <c:if test="${nodeJd.isWarning != 1}">否</c:if>--%>
                </td>

                <td><input type="hidden" value="${nodeJd.isKey}">
                    <c:if test="${nodeJd.isKey == 1}">是</c:if>
                    <c:if test="${nodeJd.isKey != 1}">否</c:if>
                </td>
                <td>
                    <%--<a href="javascript:void(0)" onclick="moveFun(this,2)">下移</a>--%>
                </td>
                <td>
                    <%--<a href="javascript:void(0)" class="dggui-icon-btn" onclick="removeRow(this)"><i class="iconfont icon-shanchu"></i></a>--%>
                    <a href="javascript:void(0)" class="dggui-icon-btn" onclick="addRow(this)" ><i class="iconfont icon-tianjia"></i></a>
                </td>
                    <input type="hidden" value="${nodeJd.id}" class="hiddenVal">
                    <input type="hidden" value="${nodeJd.relationFieldIds}" class="hiddenSetVal">
            </tr>
            <c:forEach items="${nodeList}" var="nodef">
                <tr>
                   <%-- <input type="hidden" value="${nodef.id}">--%>
                    <td>${nodef.sort}</td>
                    <td><input type="text" class="dggui-input" value="${nodef.name}"></td>
                    <td><input type="number" class="dggui-input" max="10000" min="0" value="${nodef.handleDate}"></td>
                    <td>
                        <select class="dggui-select">
                            <option value="1" <c:if test="${nodef.isNaturalorWorkday == 1}">selected</c:if>>工作日</option>
                            <option value="2" <c:if test="${nodef.isNaturalorWorkday == 2}">selected</c:if>>自然日</option>
                        </select>
                    </td>
                    <td>
                        <c:if test="${empty nodef.relationField}">
                            <a href="javascript:void(0)" class="dggui-link dggui-icon-btn" onclick="relevanceCode(this)"><i class="iconfont icon-tianjia"></i><span>添加关联字段</span></a>
                        </c:if>
                        <c:if test="${not empty nodef.relationField}">
                        <span class="relevance">
                                ${nodef.relationField}
                        </span>
                            <a href="javascript:void(0)" class="dggui-icon-btn" onclick="relevanceCode(this,'${nodef.relationFieldIds}')"><i class="iconfont icon-bianji1"></i></a>
                        </c:if>
                    </td>

                   <td>
                       <select class="dggui-select">
                           <option value="1" <c:if test="${nodef.isPunish == 1}">selected</c:if>>是</option>
                           <option value="2" <c:if test="${nodef.isPunish == 2}">selected</c:if>>否</option>
                       </select>
                   </td>
                   <td>
                       <select class="dggui-select">
                           <option value="">请选择</option>
                           <c:forEach items="${kfList}" var="kfList">
                               <option value="${kfList.id}" <c:if test="${nodef.punishId == kfList.id}">selected</c:if>>${kfList.name}</option>
                           </c:forEach>
                       </select>
                       <%--<select class="dggui-select">
                           <option value="1" <c:if test="${nodef.punishId == 1}">selected</c:if>>是</option>
                           <option value="2" <c:if test="${nodef.punishId == 2}">selected</c:if>>否</option>
                       </select>--%>
                   </td>
                   <td>
                       <select class="dggui-select">
                           <option value="1" <c:if test="${nodef.isWarning == 1}">selected</c:if>>是</option>
                           <option value="2" <c:if test="${nodef.isWarning == 2}">selected</c:if>>否</option>
                       </select>
                   </td>

                    <td>
                        <select class="dggui-select">
                            <option value="1" <c:if test="${nodef.isKey == 1}">selected</c:if>>是</option>
                            <option value="2" <c:if test="${nodef.isKey == 2}">selected</c:if>>否</option>
                        </select>
                    </td>
                    <td>
                        <a href="javascript:void(0)" onclick="moveFun(this,1)">上移</a>
                        <a href="javascript:void(0)" onclick="moveFun(this,2)">下移</a>
                    </td>
                    <td>
                        <a href="javascript:void(0)" class="dggui-icon-btn" onclick="removeRow(this)"><i class="iconfont icon-shanchu"></i></a>
                        <a href="javascript:void(0)" class="dggui-icon-btn" onclick="addRow(this)" ><i class="iconfont icon-tianjia"></i></a>
                    </td>
                       <input type="hidden" value="${nodef.id}" class="hiddenVal">
                       <input type="hidden" value="${nodef.relationFieldIds}" class="hiddenSetVal">
                </tr>
            </c:forEach>
            <c:if test="${not empty nodeFk}">
            <tr>
                <%--<input type="hidden" value="${nodeQzWj.id}">--%>
                <td>${nodeFk.sort}</td>
                <td>${nodeFk.name}</td>
                <td><input type="number" class="dggui-input" max="10000" min="0" value="${nodeFk.handleDate}"></td>
                <td>
                    <select class="dggui-select">
                        <option value="1" <c:if test="${nodeFk.isNaturalorWorkday == 1}">selected</c:if>>工作日</option>
                        <option value="2" <c:if test="${nodeFk.isNaturalorWorkday == 2}">selected</c:if>>自然日</option>
                    </select>
                </td>
                <td>
                    <c:if test="${empty nodeFk.relationField}">
                        <a href="javascript:void(0)" class="dggui-link dggui-icon-btn" onclick="relevanceCode(this)"><i class="iconfont icon-tianjia"></i><span>添加关联字段</span></a>
                    </c:if>
                    <c:if test="${not empty nodeFk.relationField}">
                        <span class="relevance">
                                ${nodeFk.relationField}
                        </span>
                        <a href="javascript:void(0)" class="dggui-icon-btn" onclick="relevanceCode(this,'${nodeFk.relationFieldIds}')"><i class="iconfont icon-bianji1"></i></a>
                    </c:if>
                </td>

                <td>
                    <select class="dggui-select">
                        <option value="1" <c:if test="${nodeFk.isPunish == 1}">selected</c:if>>是</option>
                        <option value="2" <c:if test="${nodeFk.isPunish == 2}">selected</c:if>>否</option>
                    </select>
                </td>
                <td>
                    <select class="dggui-select">
                        <option value="">请选择</option>
                        <c:forEach items="${kfList}" var="kfList">
                            <option value="${kfList.id}" <c:if test="${nodeFk.punishId == kfList.id}">selected</c:if>>${kfList.name}</option>
                        </c:forEach>
                    </select>
                </td>
                <td>
                    <select class="dggui-select">
                        <option value="1" <c:if test="${nodeFk.isWarning == 1}">selected</c:if>>是</option>
                        <option value="2" <c:if test="${nodeFk.isWarning == 2}">selected</c:if>>否</option>
                    </select>
                </td>
                <td>
                    <input type="hidden" value="${nodeFk.isKey}"/>
                    <c:if test="${nodeFk.isKey == 1}">是</c:if>
                    <c:if test="${nodeFk.isKey != 1}">否</c:if>
                    <%--<select class="dggui-select">
                        <option value="1" <c:if test="${nodeFk.isKey == 1}">selected</c:if>>是</option>
                        <option value="2" <c:if test="${nodeFk.isKey == 2}">selected</c:if>>否</option>
                    </select>--%>
                </td>
                <td>
                    <%--<a href="javascript:void(0)" onclick="moveFun(this,1)">上移</a>
                    <a href="javascript:void(0)" onclick="moveFun(this,2)">下移</a>--%>
                </td>
                <td>
                    <%--<a href="javascript:void(0)" class="dggui-icon-btn" onclick="removeRow(this)"><i class="iconfont icon-shanchu"></i></a>
                    <a href="javascript:void(0)" class="dggui-icon-btn" onclick="addRow(this)" ><i class="iconfont icon-tianjia"></i></a>--%>
                </td>
                <input type="hidden" value="${nodeFk.id}" class="hiddenVal">
                <input type="hidden" value="${nodeFk.relationFieldIds}" class="hiddenSetVal">
            </tr>
            </c:if>
            <tr>
               <%-- <input type="hidden" value="${nodeWj.id}">--%>
                <td>${nodeWj.sort}</td>
                <td>${nodeWj.name}</td>
                <td><input type="number" class="dggui-input" max="10000" min="0" value="${nodeWj.handleDate}"></td>
                <td>
                    <select class="dggui-select">
                        <option value="1" <c:if test="${nodeWj.isNaturalorWorkday == 1}">selected</c:if>>工作日</option>
                        <option value="2" <c:if test="${nodeWj.isNaturalorWorkday == 2}">selected</c:if>>自然日</option>
                    </select>
                </td>
                <td>
                    <c:if test="${empty nodeWj.relationField}">
                        <a href="javascript:void(0)" class="dggui-link dggui-icon-btn" onclick="relevanceCode(this)"><i class="iconfont icon-tianjia"></i><span>添加关联字段</span></a>
                    </c:if>
                    <c:if test="${not empty nodeWj.relationField}">
                        <span class="relevance">
                                ${nodeWj.relationField}
                        </span>
                        <a href="javascript:void(0)" class="dggui-icon-btn" onclick="relevanceCode(this,'${nodeWj.relationFieldIds}')"><i class="iconfont icon-bianji1"></i></a>
                    </c:if>
                </td>
               <td>
                   <select class="dggui-select">
                       <option value="1" <c:if test="${nodeWj.isPunish == 1}">selected</c:if>>是</option>
                       <option value="2" <c:if test="${nodeWj.isPunish == 2}">selected</c:if>>否</option>
                   </select>
               </td>
               <td>
                   <select class="dggui-select">
                       <option value="">请选择</option>
                       <c:forEach items="${kfList}" var="kfList">
                           <option value="${kfList.id}" <c:if test="${nodeWj.punishId == kfList.id}">selected</c:if>>${kfList.name}</option>
                       </c:forEach>
                   </select>
               </td>
               <td>
                   <select class="dggui-select">
                       <option value="1" <c:if test="${nodeWj.isWarning == 1}">selected</c:if>>是</option>
                       <option value="2" <c:if test="${nodeWj.isWarning == 2}">selected</c:if>>否</option>
                   </select>
               </td>
                <td>
                    <input type="hidden" value="${nodeWj.isKey}"/>
                    <c:if test="${nodeWj.isKey == 1}">是</c:if>
                    <c:if test="${nodeWj.isKey != 1}">否</c:if>
                    <%--<select class="dggui-select">
                        <option value="1" <c:if test="${nodeWj.isKey == 1}">selected</c:if>>是</option>
                        <option value="2" <c:if test="${nodeWj.isKey == 2}">selected</c:if>>否</option>
                    </select>--%>
                </td>
                <td>
                   <%-- <a href="javascript:void(0)" onclick="moveFun(this,1)">上移</a>--%>
                </td>
                <td>
                    <%--<a href="javascript:void(0)" class="dggui-icon-btn" onclick="removeRow(this)"><i class="iconfont icon-shanchu"></i></a>
                    <a href="javascript:void(0)" class="dggui-icon-btn" onclick="addRow(this)" ><i class="iconfont icon-tianjia"></i></a>--%>
                </td>
                   <input type="hidden" value="${nodeWj.id}" class="hiddenVal">
                   <input type="hidden" value="${nodeWj.relationFieldIds}" class="hiddenSetVal">
            </tr>
            </tbody>
        </table>
        <div class="txt-center">
            <button class="dggui-btn" onclick="saveNodeFlow();">保存</button>
        </div>
    </div>
</div>
<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script>

    dggui.use(['jquery','dialog'],function () {
    })
    //新增行
    function addRow(obj) {
        var trHtm='<tr>' +
            '            <td><input type="text" class="dggui-input" /></td>\n' +
            '            <td><input type="text" class="dggui-input" /></td>\n' +
            '            <td><input type="number" class="dggui-input"  max="10000" min="0"/></td>\n' +
            '            <td>\n' +
            '                <select class="dggui-select">\n' +
            '                    <option value="1">工作日</option>\n' +
            '                    <option value="2">自然日</option>\n' +
            '                </select>\n' +
            '            </td>' +
            '            <td>' +
            '               <a href="javascript:void(0)" class="dggui-link dggui-icon-btn" onclick="relevanceCode(this)"><i class="iconfont icon-tianjia"></i><span>添加关联字段</span></a>' +
            '           </td>' +
            '           <td>' +
            '               <select class="dggui-select">' +
            '                   <option value="2">否</option>' +
            '                   <option value="1">是</option>' +
            '               </select>' +
            '           </td>'+
            '           <td>' +
            '               <select class="dggui-select" name="punishSelected">' +
            '                   <option value="">请选择</option>' +
            '               </select>' +
            '           </td>'+
            '           <td>' +
            '               <select class="dggui-select">' +
            '                   <option value="2">否</option>' +
            '                   <option value="1">是</option>' +
            '               </select>' +
            '           </td>'+
            '           <td>' +
            '               <select class="dggui-select">' +
            '                   <option value="2">否</option>' +
            '                   <option value="1">是</option>' +
            '               </select>' +
            '           </td>'+
            '            <td>\n' +
            '                <a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,1)">上移</a>\n' +
            '                <a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,2)">下移</a>\n' +
            '            </td>\n' +
            '            <td>\n' +
            '                <a href="javascript:void(0)" class="dggui-icon-btn" onclick="removeRow(this)"><i class="iconfont icon-shanchu"></i></a>\n' +
            '                 <a href="javascript:void(0)" class="dggui-icon-btn" onclick="addRow(this)" ><i class="iconfont icon-tianjia"></i></a>' +
            '            </td>\n' +
            '            <input type="hidden" class="hiddenVal"/>\n' +
            '             <input type="hidden" class="hiddenSetVal">\n' +
            '        </tr>'
        $(obj).parents('tr').after(trHtm);
        tableEach();
        punishSelected(obj);
    }
    function punishSelected(obj){
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath + '/rzsc/punish/query_punish_json.do',
            type:'post',
            data:{code:"${rzFlow.bigformatCode}"},
            dataType:'json',
            success:function(data){
                dggui.dialog.loading('close');
                var htmlStr = '<option value="">请选择</option>';
                if(data.code == 0){
                    var datas = data.data;
                    $(datas).each(function(j){
                        htmlStr += '<option value="'+datas[j].id+'">'+datas[j].name+'</option>';
                    });
                    $(obj).parents('tr').next().find("[name=punishSelected]").html(htmlStr);
                }else{
                    dggui.dialog.errors('获取数据失败，请刷新页面重试！！');
                }
            },
            error:function(){
                dggui.dialog.loading('close');
                dggui.dialog.errors('获取数据失败，请联系管理员！！');
            }
        });
    }
    //删除行
    function removeRow(obj) {
        $(obj).parents('tr').remove();
        tableEach()
    }
    //上下移动行
    function moveFun(obj,move) {
        var num = $(obj).parents('tr').find('td').first().text();
        var totalNum=$('.nodeTable').find('tbody').find('tr').length;
        if((num == 1 || num == 2) && move == 1){
            return;
        }
        if((num == totalNum || num == totalNum-1 || num == totalNum-2) && move == 2){
            return;
        }
        var trHtm=$(obj).parents('tr').html();
        trHtm='<tr>'+trHtm+'</tr>';
        /*获取移动行内输入框的val*/
        var tdLen=$(obj).parents('tr').find('td').length-2;
        var tdData={};
        $(obj).parents('tr').find('td').each(function (i) {
            if(i<tdLen) {
                tdData[i]=$(this).children().val();
            }
        });
        if(move==1) {
            //上移
            $(obj).parents('tr').prev().before(trHtm);
            $(obj).parents('tr').prev().prev().find('td').each(function (j) {
                $(this).children().val(tdData[j])
            })
        }
        else {
            //下移
            $(obj).parents('tr').next().after(trHtm);
            $(obj).parents('tr').next().next().find('td').each(function (j) {
                $(this).children().val(tdData[j])
            })
        }
        $(obj).parents('tr').remove();
        tableEach();
    }
    function tableEach(obj) {
        var trLen=$('.nodeTable').find('tbody').find('tr').length;
        if(trLen==1){
            $('.nodeTable').find('tbody').find('tr').children().eq(4).hide();
        }else {
            $('.nodeTable').find('tbody').find('tr').children().eq(4).show();
        }
        $('.nodeTable').find('tbody').find('tr').each(function (i) {
            $(this).children().eq(0).text(i+1)
            if(i==0) {
                //$(this).children().eq(6).empty().append('<a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,2)">下移</a>');
            }else if(i==trLen-1) {
                //$(this).children().eq(6).empty().append('<a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,1)">上移</a>')
            }else if(i==trLen-2){
                //$(this).children().eq(6).empty().append('<a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,1)">上移</a>')
            }else {
                $(this).children().eq(9).empty().append('<a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,1)">上移</a>' +
                    '<a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,2)">下移</a>');
            }
        })
    }
    //    添加关联字段
    function relevanceCode(obj,str) {
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath + '/rzsc/flow/query_node_field_list.do',
            dataType:'json',
            success:function (data) {
                if(data.code == 0){
                    data = data.data;
                    var htm='<div class="dialog-warp-ajax">';
                    for(var key in data) {
                        htm+='<a href="javascript:void(0)" class="list-tag" data-id="'+data[key].id+'">'+data[key].fieldName+'</a>';
                    }
                    htm+='</div>';
                    dggui.dialog.open({
                        title:'添加关联字段',
                        content:htm,
                        area:'700px',
                        success:function (layero,index) {
                            dggui.dialog.loading('close');
                            if (str!=undefined&&str!='') {
                                var arr=str.split(',');
                                for(var i=0;i<arr.length;i++) {
                                    $(layero).find('.list-tag[data-id="'+arr[i]+'"]').addClass('active')
                                }
                            }
                            $(layero).find('.list-tag').click(function () {
                                var isActive=$(this).hasClass('active');
                                if(isActive) {
                                    $(this).removeClass('active');
                                }else {
                                    $(this).addClass('active');
                                }
                            })
                        },
                        yes:function (index,layero) {
                            var res=[];
                            var txt='',id='';
                            $(layero).find('.list-tag.active').each(function (i) {
                                i++;
                                txt+=i+'.'+$(this).text()+'；';
                                id+=$(this).data('id')+','
                                console.log($(this).text())
                                var resList={};
                                resList.id=$(this).data("id");
                                resList.name=$(this).text();

                                res.push(resList);
                            });

                            console.log(res)
                            $(obj).parents('td').find('.relevance').remove();
                            $(obj).before('<span class="relevance">'+txt+'</span>');
                            if(res.length==0) {
                                $(obj).after('<a href="javascript:void(0)" class="dggui-link dggui-icon-btn" onclick="relevanceCode(this)"><i class="iconfont icon-tianjia"></i><span>添加关联字段</span></a>');
                            }else {
                                $(obj).after('<a href="javascript:void(0)" class="dggui-icon-btn" onclick="relevanceCode(this,\''+id+'\')"><i class="iconfont icon-bianji1"></i></a>');
                            }
                            setVal(res,obj);
                            $(obj).remove();
                            layer.close(index)
                        }
                    })
                }
            }
        })
    }
    function setVal(res,obj){
        var ids = '';
        if(res.length>0){
            for(i=0;i<res.length;i++){
                if(i == res.length-1){
                    ids += res[i].id;
                }else{
                    ids += res[i].id+",";
                }
            }
        }
        $(obj).parents('tr').find('.hiddenSetVal').val(ids);
    }
    function ObjStory(nodeid, xuhao, nodename, nodecycle, isNaturalorWorkday, nodecruxfield, nodecruxfieldids, iscurxnode, isPunish, punishId, punishName, isWarning) //声明对象
    {
        this.nodeid = nodeid;
        this.Xuhao = xuhao;
        this.Nodename = nodename;
        this.Nodecycle = nodecycle;
        this.isNaturalorWorkday = isNaturalorWorkday;
        this.Nodecruxfield = nodecruxfield;
        this.nodecruxfieldids = nodecruxfieldids;
        this.Iscurxnode = iscurxnode;
        this.isPunish = isPunish;
        this.punishId = punishId;
        this.punishName = punishName;
        this.isWarning = isWarning;

    }
    function saveNodeFlow(){
        var reg = /^[1-9]\d*$/;
        var flowid = '${rzFlow.id}';//流程ID
        var trList = $("#tb").children("tr");
        var tableparms = new Array();
        for (var i = 0; i < trList.length; i++) {
            var nodeid = trList.eq(i).find(".hiddenVal").val();
            var nodecruxfieldids = trList.eq(i).find(".hiddenSetVal").val();

            var tdArr = trList.eq(i).find("td");
            var xuhao = $.trim(tdArr.eq(0).text());//序号
            var nodename = '';//节点名称
            var nodecycle = '';//节点办理周期
            var isNaturalorWorkday ='';//    工作日/自然日
            var iscurxnode = ''//    是否关键节点

            var isPunish = "";//是否扣罚
            var punishId = "";//扣罚ID
            var punishName = "";//扣罚方案名称
            var isWarning = "";//是否预警
            var nodecruxfield = trList.eq(i).find(".relevance").text();
            if(i == 0){
                nodename = tdArr.eq(1).text().trim();
                nodecycle = tdArr.eq(2).text();
                isNaturalorWorkday = tdArr.eq(3).find('input').val();
                iscurxnode = tdArr.eq(8).find('input').val();
                isPunish = tdArr.eq(5).find('select').val();
                punishId = tdArr.eq(6).find('select').val();
                punishName = tdArr.eq(6).find('select').find("option:selected").text();
                isWarning = tdArr.eq(7).find('select').val();
            }else if(i == trList.length-1 || i == trList.length-2){
                nodename = tdArr.eq(1).text().trim();
                nodecycle = tdArr.eq(2).find('input').val();
                isNaturalorWorkday = tdArr.eq(3).find('select').val()
                iscurxnode = tdArr.eq(8).find('input').val();
                isPunish = tdArr.eq(5).find('select').val();
                punishId = tdArr.eq(6).find('select').val();
                punishName = tdArr.eq(6).find('select').find("option:selected").text();
                isWarning = tdArr.eq(7).find('select').val();
            }else{
                nodename = tdArr.eq(1).find('input').val().trim();
                nodecycle = tdArr.eq(2).find('input').val();
                isNaturalorWorkday = tdArr.eq(3).find('select').val()
                iscurxnode = tdArr.eq(8).find('select').val();
                isPunish = tdArr.eq(5).find('select').val();
                punishId = tdArr.eq(6).find('select').val();
                punishName = tdArr.eq(6).find('select').find("option:selected").text();
                isWarning = tdArr.eq(7).find('select').val();
            }


            if (!nodename) {
                dggui.dialog.errors('请确认节点名称是否完整！');
                return;
            }
            if(nodename.length>10){
                dggui.dialog.errors('节点名称不能超过10个字！');
                return;
            }
            if(!reg.test(nodecycle)){
                dggui.dialog.errors('请输入正确的节点办理周期！');
                return;
            }
            if (!nodecycle) {
                dggui.dialog.errors('请确认节点办理周期是否完整！');
                return;
            }
            if(parseInt(nodecycle)>10000){
                dggui.dialog.errors('节点办理周期不能大于10000天！');
                return;
            }
            if(isPunish == 1 && punishId == ""){
                dggui.dialog.errors('请为名称为【'+nodename+'】选择扣罚方案！');
                return;
            }
            var parm = new ObjStory(nodeid, xuhao, nodename, nodecycle, isNaturalorWorkday, nodecruxfield, nodecruxfieldids, iscurxnode,isPunish, punishId, punishName, isWarning);//声明对象
            tableparms[i] = parm;
        }
        var json = JSON.stringify(tableparms);
        var params = $('#addProcess').serializeArray();
        var version = "${nodeJd.version}";
        params.push({name: 'jsonData', value: json});
        params.push({name: 'flowid', value: flowid});
        params.push({name:'version',value:version});
        dggui.dialog.loading();
        $.ajax({
            type: 'POST',
            async: true,
            data: params,
            url: sysInfo.basePath + '/rzsc/flow/nodesave.do',
            dataType: 'JSON',
            success: function (data) {
                dggui.dialog.loading('close');
                if (data.code == 0) {
                    dggui.dialog.succeed('操作成功！');
                    setTimeout("location.reload()",1300);
                } else {
                    dggui.dialog.errors(data.msg);
                }
            },
            error: function () {
                dggui.dialog.loading('close');
                dggui.dialog.errors('保存失败，请联系管理员！！');
            }
        })
    }
</script>
</body>
</html>